<?php

declare(strict_types=1);

function result(int $code, string $message, array $data): array
{
    return [
        'code' => $code,
        'message' => $message,
        'data' => $data,
    ];
}

function responseSuccess(int $code = 200, string $message = '', array $data = []): array
{
    if (empty($message)) {
        return result($code, \App\Constants\ResponseCode::getMessage($code), $data);
    }

    return result($code, $message, $data);
}

/**
 * 错误返回.
 */
function responseError(int $code = 422, string $message = '', array $data = []): array
{
    if (empty($message)) {
        return result($code, \App\Constants\ResponseCode::getMessage($code), $data);
    }

    return result($code, $message, $data);
}
